#-*- coding: utf-8 -*-
'''
    Author: hkk
'''
from django.shortcuts import render_to_response, HttpResponseRedirect, HttpResponse, render, reverse
import json
import collections
import datetime
from content.models import Content, Type, Project
from django.conf import settings
from cmdb.models import Server
from vmware.models import vmware_content,vmware_resource

from release.models import AppProject
from accounts.models import User
import  simplejson
from django.contrib.auth.decorators import permission_required, login_required, user_passes_test

@login_required()
def index(request):

    sumusers=User.objects.filter(is_active=1).count()
    sumhosts=Server.objects.filter().count()
    sumvhosts=vmware_content.objects.filter(vm_status=1).count()
    sumapp=AppProject.objects.filter().count()
    
    request.breadcrumbs((('首页', '/'), ('仪表盘', reverse('dashboard_index'))))
    return render_to_response('dashboard/index.html', {'request': request,'sumusers':sumusers,'sumhosts':sumhosts,'sumvhosts':sumvhosts,'sumapp':sumapp})



def get_cpu_info(request):
    if request.method == "POST":

        result1={'已使用':'13','未使用':'40'}
        result = simplejson.dumps(result1)
        return HttpResponse(result)

def get_mem_info(request):
    if request.method == "POST":
        result1={'已使用':'123','未使用':'40'}
        result = simplejson.dumps(result1)
        return HttpResponse(result)


def get_disk_info(request):
    if request.method == "POST":
        result1={'已使用':'98','未使用':'4'}
        result = simplejson.dumps(result1)
        return HttpResponse(result)

def get_serversinfo(request):
     if request.method == "POST":
        result1={'何宽宽':'2','谢伟':'4','张跃':'2','周春寅':'5','展昭':'2','王家勇':'2','徐金凤':'4','杨培韬':'1','谢永亮':'2','胡兴':'3'}
        result = simplejson.dumps(result1)
        return HttpResponse(result)



